package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaCompany;
import com.sailfish.springbootdemo.pojo.db1.PcbaWorkshop;
import com.sailfish.springbootdemo.service.db1.PcbaCompanyService;
import com.sailfish.springbootdemo.service.db1.PcbaWorkshopService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/pcbaWorkshop")
public class PcbaWorkshopController {

    @Autowired
    private PcbaWorkshopService pcbaWorkshopService;

    @Autowired
    private PcbaCompanyService pcbaCompanyService;

    @PostMapping("/getAllPcbaWorkshopByCompanyId")
    public Result getAllPcbaWorkshopByCompanyId(String searchValue, Integer pcbaCompanyId) {
        try {
            /*if(pcbaCompanyId == null || "".equals(pcbaCompanyId.toString())){
                return ResultUtil.error(500, "缺少参数pcbaCompanyId", "Miss Param pcbaCompanyId", null);
            }*/
            return ResultUtil.success(pcbaWorkshopService.getAllPcbaWorkshopByCompanyId(searchValue, pcbaCompanyId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deleteWorkshop")
    public Result deleteWorkshop(Integer pcbaWorkshopId) {
        try {
            if (pcbaWorkshopId == null || "".equals(pcbaWorkshopId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaWorkshopId", "Miss Param pcbaWorkshopId", null);
            }
            return pcbaWorkshopService.deleteWorkshop(pcbaWorkshopId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/addOrUpdatePcbaWorkshop")
    public Result addOrUpdatePcbaWorkshop(String mode, PcbaWorkshop pcbaWorkshop) {
        return pcbaWorkshopService.addOrUpdatePcbaWorkshop(mode, pcbaWorkshop);
    }
}
